Using Overriding Styles, Inks, and Transforms
As detailed in the previous three sections, QuickDraw GX provides a number of methods for adding items to a picture shape. In particular, you can add items when creating a picture using theGXNewPicture
function, you can replace every item in an existing picture using theGXSetPicture
function, and you can replace some of the items in a picture using theGXSetPictureParts
function. All three of these functions allow you to specify overriding styles, inks, and transforms for the new picture items.As an example, the code in Listing 6-8 and Listing 6-9 alters the house picture from Listing 6-1 on page 6-28. Listing 6-8 defines a style object, an ink object, and a transform object. Listing 6-9 uses these objects and the
GXSetPicture
function to create a house picture whose items contain overriding styles, inks, and transforms.Listing 6-8 Creating style, ink, and transform objects
gxShape squarePattern; gxStyle patternedStyle; gxInk grayInk; gxTransform skewedTransform; const gxRectangle squareGeometry = {ff(0), ff(0), ff(2), ff(2)}; gxPatternRecord patternRecord; . . . squarePattern = GXNewRectangle(&squareGeometry); patternRecord.attributes = gxNoAttributes; patternRecord.pattern = squarePattern; patternRecord.u.x = ff(1); patternRecord.u.y = ff(4); patternRecord.v.x = ff(3); patternRecord.v.y = ff(1); patternedStyle = GXNewStyle(); GXSetStylePattern(patternedStyle, &patternRecord); grayInk = GXNewInk(); SetInkCommonColor(grayInk, gxGray); skewedTransform = GXNewTransform(); GXSkewTransform(skewedTransform, -fl(.5), 0, ff(122), ff(110));Listing 6-9 uses the style, ink, and transform objects defined in Listing 6-8, and thepartsOfHouse
array (which is defined in Listing 6-1 on page 6-28) to create a house picture. In this house picture, the main part of the house has an overriding style, the roof has an overriding ink, and the door has an overriding transform.Listing 6-9 Creating a picture whose items have overriding styles, inks, and transforms
gxStyle overridingStyles[3]; gxInk overridingInks[3]; gxTransform overridingTransforms[3]; . . . overridingStyles[0] = patternedStyle; overridingStyles[1] = nil; overridingStyles[2] = nil; overridingInks[0] = nil; overridingInks[1] = grayInk; overridingInks[2] = nil; overridingTransforms[0] = nil; overridingTransforms[1] = nil; overridingTransforms[2] = skewedTransform; housePicture = GXNewShape(gxPictureType); GXSetPicture(housePicture, 3, partsOfHouse, overridingStyles, overridingInks, overridingTransforms);Once you have added the overriding style, ink, and transform objects to the picture, you can dispose of them, as shown in Listing 6-10. Since these objects are referenced twice (once by your application and once by the house picture), disposing of them lowers their owner counts to 1, but does not free the memory associated with them. When you eventually dispose of the house picture, QuickDraw GX disposes of these objects again and frees their memory.Listing 6-10 Disposing of overriding style, ink, and transform objects before drawing
GXDisposeShape(squarePattern); GXDisposeStyle(patternedStyle); GXDisposeInk(grayInk); GXDisposeTransform(skewedTransform); GXDrawShape(housePicture);The resulting picture is shown in Figure 6-24.Figure 6-24 A house picture with an overriding style, ink, and transform
For more information about overriding styles, inks, and transforms, see "Overriding Styles, Inks, and Transforms" beginning on page 6-8.
For more information about the
GXNewPicture
function, see page 6-57. For more information about theGXSetPicture
function, see page 6-61.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help